package com.litian.dancechar.base.blacklist.controller;

import com.litian.dancechar.base.blacklist.dto.SysBlackListAddOrEditDTO;
import com.litian.dancechar.base.blacklist.dto.SysBlackListReqDTO;
import com.litian.dancechar.base.blacklist.dto.SysBlackListRespDTO;
import com.litian.dancechar.base.blacklist.service.SysBlackListService;
import com.litian.dancechar.framework.common.base.PageWrapperDTO;
import com.litian.dancechar.framework.common.base.RespResult;
import com.litian.dancechar.framework.common.base.RespResultCode;
import com.litian.dancechar.framework.common.validator.ValidatorUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 黑名单地址业务处理
 *
 * @author litian
 * @date 2021/6/19 11:17
 */
@Api(value = "黑名单地址相关controller")
@RestController
@Slf4j
@RequestMapping(value = "/sys/blacklist/")
public class SysBlackListController {
    @Resource
    private SysBlackListService sysBlackListService;

    @ApiOperation(value = "分页查询黑名单列表", notes = "分页查询黑名单列表")
    @PostMapping("listPaged")
    public RespResult<PageWrapperDTO<SysBlackListRespDTO>> listPaged(@RequestBody SysBlackListReqDTO req) {
        try {
            return sysBlackListService.listPaged(req);
        } catch (Exception e) {
            log.error("分页查询黑名单列表系统异常!errMsg:{}", e.getMessage(), e);
            return RespResult.error(RespResultCode.SYS_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询黑名单列表", notes = "查询黑名单列表")
    @PostMapping("findList")
    public RespResult<List<SysBlackListRespDTO>> findList(@RequestBody SysBlackListReqDTO req) {
        try {
            return sysBlackListService.findList(req);
        } catch (Exception e) {
            log.error("查询黑名单列表系统异常!errMsg:{}", e.getMessage(), e);
            return RespResult.error(RespResultCode.SYS_EXCEPTION);
        }
    }

    @ApiOperation(value = "新增或修改黑名单保存", notes = "新增或修改黑名单保存")
    @PostMapping("save")
    public RespResult<Boolean> save(@RequestBody SysBlackListAddOrEditDTO req) {
        log.info("进入新增或修改黑名单....");
        ValidatorUtil.validate(req);
        try {
            return sysBlackListService.save(req);
        } catch (Exception e) {
            log.error("新增或修改黑名单保存系统异常!errMsg:{}", e.getMessage(), e);
            return RespResult.error(RespResultCode.SYS_EXCEPTION);
        }
    }
}